library(tidyverse)
library(modelsummary)
library(kableExtra)

step_data <- read_csv("data/model/output/PPFEStepValues.csv") 
table_out <- 'output/figures/model/AlternateCosts/StepFunction/'

# Table of fixed effects statistics
step_data %>%
  slice_head(n=1, by=c("id_period", "id_plant")) %>%
  select(id_period, pp_avg_p) %>%
  datasummary((`Period` = Factor(id_period)) ~
                (` ` = pp_avg_p)*(Mean+SD+Min+P25+Median+P75+Max),
              data=.,
              escape = T,
              align = "lccccccc",
              note = "All statistics are for plant FEs inside the given period.",
              output = "kableExtra",
              format = "latex") %>%
  kable_styling(latex_options = c("hold_position")) %>%
  write_lines(str_c(table_out,"fixed_effects_table.tex"))

# Code to help understand model results
step_data %>%
  filter(id_level==3e5) %>%
  select(Eit, id_period, id_plant, Et, Pt, Zt)
  pull(Eit) %>%
  sum()
